package org.richin.collection.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
/**
 * 支持模糊搜索的HashMap
 * @author qw
 * 
 * @param <K>
 * @param <V>
 */
public class MyLikeHashMap<K, V> extends HashMap<K, V> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8543568152646669773L;
	public List<V> get(String key,boolean like)
	{
		List<V> list=null;
		if(like)
		{
			list=new ArrayList<V>();
			K[] a=null;
			Set<K> set=this.keySet();
			a=(K[])set.toArray();
			Arrays.sort(a,null);
			for(int i=0;i<a.length;i++)
			{
				if(a[i].toString().indexOf(key)==-1)
					continue;
				else
					list.add(this.get(key));
			}
		}
		return list;
		
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	      MyLikeHashMap<String, String> mh = new MyLikeHashMap<String, String>(); 
	        for (int i = 0; i < 100000; i++) { 
	            mh.put("A_" + i, "AAAAAA" + i); 
	        } 
	        long time = System.currentTimeMillis(); 
	        System.out.println(mh.get("A", true).size()); 
	        System.out.println(System.currentTimeMillis() - time); 

	}

}
